<?php

if(! defined('OT_ROOT')) {
	exit('Access Denied');
}


class TemplateOTCMS{
	public $copyright		= '请限自己研究和使用，不要传播，国产自主研发产品不易也很脆弱，经不起盗版的破坏。';
	public $tplDirFileArr	= array();

	public function __construct(){

	}

	// 变量赋值
	public function Add($strId,$strCont){
		$this->obj->assign($strId,$strCont);
	}

	// 注册自定义函数
	public function RegFunc(){
		if ($this->isRegPlu){ return; }
		$this->obj->registerPlugin('function','diyFunc','DiyFunction');
		$this->isRegPlu = true;
	}

	// 显示模板
	public function Show($tplName){
		$this->obj->display($tplName);
	}

	// 获取要输出的模板内容
	public function GetShow($tplName){
		return $this->obj->fetch($tplName);
	}

	// 检查是否存在该文件
	public function CheckTplFile($tplName){
		if (empty($this->tplDirFileArr[$this->sysArr['SYS_templateDir']])){
			$retArr = array();
			$dirPath = OT_ROOT . $this->tplDir;
			if ($handle = opendir(OT_ROOT . $this->tplDir)) {
				if (substr($dirPath,-1) != '/'){ $dirPath .= '/'; }
				while (($file = readdir($handle)) !== false) {
					if ($file != '.' && $file != '..' && is_dir($dirPath . $file)==false && substr($file,-5)=='.html') {
						$this->tplDirFileArr[$this->sysArr['SYS_templateDir']][] = $file;
					}
				}
			}
			closedir($handle);
		}
		return in_array($tplName,$this->tplDirFileArr[$this->sysArr['SYS_templateDir']]);
	}


	// 解析页尾
	public function WebBottom(){
		// 友情链接区域
		$siteLogoArea = '';
		if (strpos($this->tplSysArr['TS_logoAreaStr'],'|'. $this->webTypeName .'|') !== false){
			$logoAddStr = $listStyleStr = '';
			if (AppLogoAdd::Jud() && $this->tplSysArr['TS_isLogoAdd'] == 1){
				$logoAddStr = '<a style="float:right;padding-right:10px;" class="font1_1" href="'. $this->webPathPart .'w.php?m=logoAdd" target="_blank">[友情链接申请]</a>';
			}
			if ($this->tplSysArr['TS_logoListMode'] >= 5){
				$listStyleStr = 'linkList linkRow'. $this->tplSysArr['TS_logoListMode'];
			}

			$siteLogoArea = '
			<div class="height5"></div>
			<div class="clr"></div>

			<div class="logoBox">
			<dl>
				<dt>'. $this->tplSysArr['TS_logoNote'] . $logoAddStr .'</dt>
				<dd class="'. $listStyleStr .'">'. TplBottom::LogoBox() .'</dd>
			</dl>
			</div>
			<div class="clr"></div>
			';
		}

		// 网站底部代码
		$siteBottomCode = '';
		if ($this->sysArr['SYS_isBaiduSitemap'] == 1){
			$siteBottomCode .= '
				<script>
				(function(){
					var bp = document.createElement("script");
					var curProtocol = window.location.protocol.split(":")[0];
					if (curProtocol === "https") {
						bp.src = "https://zz.bdstatic.com/linksubmit/push.js";
					}
					else {
						bp.src = "http://push.zhanzhang.baidu.com/push.js";
					}
					var s = document.getElementsByTagName("script")[0];
					s.parentNode.insertBefore(bp, s);
				})();
				</script>';
		}

		if ( strlen($this->tplSysArr['TS_beianName']) > 0 ){
			$beianStr = '&ensp;&ensp;<a href="'. (strlen($this->tplSysArr['TS_beianUrl']) > 0 ? 'https://beian.mps.gov.cn/#/query/webSearch?code='. $this->tplSysArr['TS_beianUrl'] : '') .'" target="_blank"><img src="'. $this->webPathPart .'inc_img/beian.png" style="margin-bottom:-5px;" />'. $this->tplSysArr['TS_beianName'] .'</a>';
		}else{
			$beianStr = '';
		}
		if ( strlen($this->tplSysArr['TS_TCP']) > 0 ){
			$tcpStr = '&ensp;&ensp;<a href="https://beian.miit.gov.cn/" target="_blank">'. $this->tplSysArr['TS_TCP'] .'</a>';
		}else{
			$tcpStr = '';
		}
		$siteCopyright = $this->tplSysArr['TS_copyright'] .
			$beianStr . $tcpStr .
			($this->tplSysArr['TS_isStati'] == 1 ? $this->tplSysArr['TS_statiCode'] : '') . (AreaApp::Jud( SysDiff::PluginId('base') )?'':'<div><span><script></script></span></div><!--  --><div style="font-size:12px;">P'.'ow'.'er'.'ed'.' b'.'y <a href="http://'. OT_SOFTTYPE .'.c'.'om/" target="_blank" title="'. SysDiff::SoftEN() .' V'. OT_VERSION .' b'.'ui'.'ld '. OT_UPDATETIME .'" style="font-size:12px;">'. SysDiff::SoftEN() .' V'. OT_VERSION .' '. OT_VERSION2 .'</a></div><!--  --><div class="clr"></div>');


		$this->Add('siteLogoArea',	$siteLogoArea);			// 友情链接模块
		$this->Add('siteBottomCode',$siteBottomCode);		// 网站底部代码
		$this->Add('siteCopyright',	$siteCopyright);		// 底部版权信息
		$this->Add('areaBottom1',	TplArea::AreaBottom1());// 底部通用区域1
//		$this->Add('siteCurrUrl',	str_replace(array('index.html','index.php'),array('',''),GetUrl::Query());
	}
}
?>